package 力扣._226_翻转二叉树;

public class Solution {
    private class TreeNode {
        int val;
        TreeNode left;
        TreeNode right;

        TreeNode() {
        }

        TreeNode(int val) {
            this.val = val;
        }

        TreeNode(int val, TreeNode left, TreeNode right) {
            this.val = val;
            this.left = left;
            this.right = right;
        }
    }
    //交换左右子树
    void swap(TreeNode root){
        if(root==null)
            return;
        TreeNode t = root.left;
        root.left = root.right;
        root.right = t;
        swap(root.left);
        swap(root.right);
    }

    public TreeNode invertTree(TreeNode root) {
        //交换左右子树值
        swap(root);
        return root;
    }
}
